package com.un.ebs.businessObject.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.un.ebs.businessObject.service.DbService;
import com.un.ebs.core.UserContextService;
import com.un.ebs.core.enums.DataTypeEnum;
import com.un.ebs.core.metadata.MetadataField;
import com.un.ebs.core.metadata.Query;
import com.un.ebs.core.metadata.ResourceData;
import com.un.ebs.core.metadata.ResourceType;
import com.un.ebs.sys.domain.Column;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author liubo
 * @create 2021-05-31 11:55
 */
public class BaseBusinessObjectService<T> {

    @Autowired
    private UserContextService userContextService;

    protected MetadataField convertToArg(Column column, MetadataField arg){
        if(column.getRefType()!=null){
            switch (column.getRefType()){
                case Diction:
                    arg.setDataType(DataTypeEnum.RESOURCE_DATA);
                    arg.setResourceCode(column.getRefDictCode());
                    arg.setResourceType(ResourceType.Dictionary);
                    arg.setResourceData(userContextService.queryDictionKey(column.getRefDictCode()));
                    break;
                case Enum:
                    arg.setDataType(DataTypeEnum.RESOURCE_DATA);
                    arg.setResourceType(ResourceType.Enum);
                    try {
                        arg.setResourceCode(Class.forName(column.getRefEnumType()).getSimpleName());
                        arg.setResourceData( ResourceData.fromEnum(Class.forName(column.getRefEnumType())));
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                    break;
            }
        }
        return arg;
    }
}
